package com.yinNuo.collectWool.core.config;

import com.yinNuo.collectWool.collectWoolHttp.ChinaUnicomHttps;
import com.yinNuo.collectWool.mobileApi.entity.WoolApps;
import com.yinNuo.collectWool.mobileApi.entity.WoolTask;
import com.yinNuo.collectWool.mobileApi.entity.WoolTaskDetail;
import com.yinNuo.collectWool.mobileApi.service.WoolTaskDetailService;
import com.yinNuo.collectWool.mobileApi.service.WoolTaskService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: yinNuo
 * create at: 2021/12/1 下午8:44
 * @description: 初始化启动器，spring启动时加载常用参数
 */
@Component
@AllArgsConstructor
@Slf4j
public class InitializeStarters implements CommandLineRunner {
    @Autowired
    WoolTaskService woolTaskService;
    @Autowired
    WoolTaskDetailService woolTaskDetailService;
    @Autowired
    private WoolApps woolApps;
    @Autowired
    ChinaUnicomHttps chinaUnicomHttps;

    //在这里写需要初始化的数据
    @Override
    public void run(String... args) throws Exception {
        //将需要的在启动服务的时候就执行

        //初始化已经加入的羊毛app
        initWoolTest();
        //初始化所有羊毛app的任务
        initWoolTestDetail();
        System.out.println("*****************CollectWoolApplication run success!*****************");
    }

    //初始化已经加入的羊毛app
    public void initWoolTest() {
        List<WoolTask> list = woolTaskService.list();
        List<Integer> woolTaskList = new ArrayList<>();
        for (WoolTask woolTask : list) {
            woolTaskList.add(woolTask.getId());
        }
        woolApps.setWoolApp(woolTaskList);
    }

    //初始化所有羊毛app的任务
    public void initWoolTestDetail() {
        List<WoolTaskDetail> list = woolTaskDetailService.list();
        List<Integer> woolTaskDetailList = new ArrayList<>();
        for (WoolTaskDetail woolTaskDetail : list) {
            woolTaskDetailList.add(woolTaskDetail.getId());
        }
    }


}
